export const idToRgba = (id: string) => id.split("-")

export const rgbaToId = (rgba: [number, number, number, number]) => rgba.join("-")

// ID池，防止ID冲突
const idPool: { [name: string]: unknown } = {};

export const createId = (): string => {
  let id = createOnceId();

  while (idPool[id]) {
    id = createOnceId();
  }

  return id;
}

const createOnceId = (): string => {
  return new Array(3)
    .fill(0)
    .map(() => Math.ceil(Math.random() * 255))
    .concat(255)
    .join("-");
}
